﻿using System;
using System.Collections.Generic;
using Medianamik.UI.Web.Shop.Data.Repositories;
using StructureMap;

namespace Medianamik.UI.Web.Shop.Data
{
    public partial class ClientProfile : Interfaces.IClientProfile
    {
        private IList<Guid> _deliveryRegions;
        private readonly  IAddressRepository<Address> _addressRepository =
            ObjectFactory.GetInstance<AddressRepository>();

        public IList<Guid> DeliveryRegions
        {
            get { return _deliveryRegions ?? (_deliveryRegions = GetDeliveryRegions()); }
        }

        private IList<Guid> GetDeliveryRegions()
        {
            var taxAddress =
            SameAddressAsPayment.GetValueOrDefault(true)
                   ? _addressRepository.Get(PaymentAddress.Value)//PaymentAddressAddressRecord)
                   : _addressRepository.Get(DeliveryAddress.Value);//DeliveryAddressAddressRecord;

            var taxRegion = new List<Guid>
            {
                taxAddress.Country.GetValueOrDefault(),
                taxAddress.State.GetValueOrDefault()
            };

            return taxRegion;
        }

                
    }
}
